/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cliente;

/**
 *
 * @author milena
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;

public class ClienteBean {
    
       protected IDatabaseConnection getConnection() throws Exception
    {
        Class driverClass = Class.forName("com.mysql.jdbc.Driver");
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/clientes", "root", "lala");
        IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
        return new DatabaseConnection(jdbcConnection);
    }
        
	void inserir(ClienteVo vo) throws ClassNotFoundException, SQLException{
            
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/clientes", "root", "lala");
        PreparedStatement s = jdbcConnection.prepareStatement("insert into clientes values (?, ?)");
        s.setInt(1, vo.getCodigo().intValue());
        s.setString(2, vo.getNome());
        s.executeUpdate();
	}
        
	void excluir(ClienteVo vo) throws ClassNotFoundException, SQLException{
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/clientes", "root", "lala");
        PreparedStatement s = jdbcConnection.prepareStatement("delete from clientes where codigo = ?");
        s.setInt(1, vo.getCodigo().intValue());
        s.executeUpdate();
	}
        
	void alterar(ClienteVo vo) throws ClassNotFoundException, SQLException{
        Connection jdbcConnection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/clientes", "root", "lala");
        PreparedStatement s = jdbcConnection.prepareStatement("update clientes set nome = ? where codigo = ?");
        s.setString(1, vo.getNome());
        s.setInt(2, vo.getCodigo().intValue());
     //   s.executeUpdate();
	}
	
}
